package com.etoak.config;

import com.etoak.common.core.properties.ImageProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.config.ResourceHandlerRegistry;
import org.springframework.web.reactive.config.WebFluxConfigurer;

@Configuration
public class WebFluxConfiguration implements WebFluxConfigurer {
    @Autowired
    ImageProperties properties;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //pics/**
        String mapping = properties.getMapping().endsWith("/") ?
                properties.getMapping() + "**" :
                properties.getMapping() + "/**";
        //file:e:/upload/et2406/
        String location = properties.getLocation().endsWith("/") ?
                "file:" + properties.getLocation() :
                "file:" + properties.getLocation() + "/";
        registry.addResourceHandler(mapping).addResourceLocations(location);
    }
}
